package gridwalking;

import java.io.*;
public class Solution {

	/**
	 * @param args
	 */
	public static void main(String[] args)  throws Exception{
		//BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		BufferedReader br = new BufferedReader(new FileReader("src/gridwalking/data.txt"));
		String line = br.readLine();
		int T = Integer.parseInt(line);
		long P[][]=new long[401][201];
		for(int ii=1;ii<=T;ii++){

			line = br.readLine();
			String str[]=line.split(" ");
			int N = Integer.parseInt(str[0]);
			int M = Integer.parseInt(str[1]);
			line = br.readLine();
			str=line.split(" ");
			int X[]=new int[N];
			for(int i=0;i<=N-1;i++){
				X[i]=Integer.parseInt(str[i]);
			}
			line = br.readLine();
			str=line.split(" ");
			int D[]=new int[N];
			for(int i=0;i<=N-1;i++){
				D[i]=Integer.parseInt(str[i]);
			}
			int result[]=solution1(M,X[0],D[0]);

			if(N==1){
				System.out.println(result[M-1]);
			}
			else{
				int result2[];
				for(int i=1;i<=N-1;i++){
					result2=solution1(M,X[i],D[i]);
					int result3[]=new int[M];
					for(int j=0;j<=M-1;j++){
						if(j==0){
							result3[j]=(int)(result[j]+result3[j])%1000000007;
							result3[j]=(int)(result2[j]+result3[j])%1000000007;
						}
						else{
							for(int k=0;k<=j-1;k++){
								int t=(int)(((long)result[k]*result2[j-k-1])%1000000007);
								t=(int)((perm(j+1,k+1,P)*t)%1000000007);
								result3[j]=(t+result3[j])%1000000007;
							}
							result3[j]=(int)(result[j]+result3[j])%1000000007;
							result3[j]=(int)(result2[j]+result3[j])%1000000007;
						}
					}
					result=result3.clone();
					result3=null;
				}
				System.out.println(result[M-1]);
			}


		}
		br.close();
	}
	public static int[] solution1(int m,int x,int d){
		int result[]=new int[m];
		if(d==1)return result;
		int a[][]=new int[2][d];
		a[0][x-1]=1;
		for(int i=1;i<=m;i++ ){
			a[i%2][d-1]=a[(i+1)%2][d-2];
			a[i%2][0]=a[(i+1)%2][1];
			for(int j=1;j<=d-2;j++){
				a[i%2][j]=(a[(i+1)%2][j-1]+a[(i+1)%2][j+1])%1000000007;
			}
			for(int k=0;k<=d-1;k++ ){
				result[i-1]=(result[i-1]+a[i%2][k])%1000000007;
			}
		}

		return result;
	}
	public static long perm(int a,int b,long[][] P){
		if(b>a/2)return perm(a,a-b,P);
		if(b==1)return a;
		if(P[a][b]!=0)return P[a][b];
		long s=1;
		int A[]=new int[b];
		for(int i=0;i<=b-1;i++){
			A[i]=a-i;
		}
		for(int i=b;i>=2;i--){
			int k=i;
			for(int j=0;j<=b-1;j++){
				int d=divider(A[j],k);
				while(d!=1){
					A[j]=A[j]/d;
					k=k/d;	
					d=divider(A[j],k);
				}
				if(k==1)break;
				if(j==b-1)System.out.println("Wrong:"+a+" "+b);

			}

		}		
		for(int i=0;i<=b-1;i++){
			s=(s*A[i])%1000000007;
		}
		P[a][b]=s;
		return s;
	}

	public static int divider(int a, int b){
		if(a<b)return divider(b,a);
		if(b==1)return 1;
		if(a%b==0)return b;
		return divider(a%b,b);
	}

}

